//
//  ReplyBackgroundView.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/26.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ReplyBackgroundView.h"
#import "BaseTableView.h"
#import "ReplyOfAnswersDataQAADetailedInformation.h"
#import "MJMacro.h"
#import "TVCellOfReplyBackView.h"
@interface ReplyBackgroundView()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UIView *view;
@property (nonatomic, assign) CGFloat heightOfReplySmallTableView;
@end
@implementation ReplyBackgroundView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
    //
    [self createSubView];
    }
    return self;
}
#pragma mark - 创建子控件
- (void)createSubView{
    self.tableViewOfReplyBackgroundView = [[BaseTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.tableViewOfReplyBackgroundView.bounces = NO;
    self.tableViewOfReplyBackgroundView.backgroundColor = [UIColor grayColor];
    [self addSubview:_tableViewOfReplyBackgroundView];
    self.tableViewOfReplyBackgroundView.delegate = self;
    self.tableViewOfReplyBackgroundView.dataSource = self;
    [self.tableViewOfReplyBackgroundView registerClass:[TVCellOfReplyBackView class] forCellReuseIdentifier:@"TVCellOfReplyBackView"];
}
#pragma mark - 代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _numberOfRowsInSection;
}
#pragma mark - 赋值方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TVCellOfReplyBackView *cell = [tableView dequeueReusableCellWithIdentifier:@"TVCellOfReplyBackView" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0f green:arc4random() % 256 / 255.0f blue:arc4random() % 256 / 255.0f alpha:1];
    cell.replyLabel.text = _mArrayOfReplyLabel[indexPath.row];
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:_mArrayOfReplyLabel[indexPath.row]];
    NSArray *array = [_mArrayOfRange[indexPath.row] componentsSeparatedByString:@"^(*￣(oo)￣)^"];
    NSRange range = {[array[0] integerValue], [array[1] integerValue]};
   
    NSLog(@"%@", array[0]);
    NSLog(@"%@", array[1]);
    NSLog(@"%@", _mArrayOfRange[indexPath.row]);
    NSLog(@"%@", _mArrayOfReplyLabel[indexPath.row]);


    [attribute addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.08 green:0.49 blue:0.98 alpha:1.00]}range:range];
    // 回复者
    NSArray *arrayOfReplyuser = [_mArrayOfRangReplyuser[indexPath.row] componentsSeparatedByString:@"^(*￣(oo)￣)^"];
    NSRange rangeOfReplyuser = {[arrayOfReplyuser[0] integerValue], [arrayOfReplyuser[1] integerValue]};
    [attribute addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.08 green:0.49 blue:0.98 alpha:1.00]}range:rangeOfReplyuser];
    [cell.replyLabel setAttributedText:attribute];
    cell.replyLabel.numberOfLines = 0;
    return cell;
}
#pragma mark - row 的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [_mArrayOfRowHeight[indexPath.row] integerValue];
}
#pragma mark - tableView 的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"我点了");
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
